﻿using NHibernate;
using OneStationFile.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OneStationFile.IBLL
{
    public interface IBaseService
    {
        /// <summary>
        /// 传入实体，并自动保存或添加
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        bool SaveOrUpdate<T>(T t);
        /// <summary>
        /// 根据传入id。获取单个model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        T GetModelById<T>(int id);
        /// <summary>
        /// 获取所有的model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IQueryOver<T> GetModels<T>() where T : class;
        /// <summary>
        /// 根据条件查询model个数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        int ExistModelByWhere<T>(Expression<Func<T, bool>> expression) where T : class;
        /// <summary>
        /// 根据id删除model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        bool DeleteModelById<T>(int id);
        /// <summary>
        /// 根据传入条件获取所有model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        List<T> GetModelsByWhere<T>(Expression<Func<T, bool>> expression) where T : class;
        /// <summary>
        /// 根据传入条件，获取单个model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="expression"></param>
        /// <returns></returns>
        T GetModelByWhere<T>(Expression<Func<T, bool>> expression) where T : class;
    }
}

